package com.dzz.sjgl.controller;

import com.dzz.sjgl.entity.PaperInfo;
import com.dzz.sjgl.service.IPaperService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author KRIC
 * @ClassName PaperController
 * @Date: 2019/3/13 11:09
 * @Description:
 */
@Controller
@ResponseBody
@RequestMapping("/paper")
public class PaperController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    private final IPaperService paperService;

    @Autowired
    public PaperController(IPaperService paperService) {
        this.paperService = paperService;
    }

    @ApiOperation(value = "获取所有试卷列表，名称模糊查询，科目准确查询")
    @ResponseBody
    @GetMapping("/getList")
    public Page<PaperInfo> getList(int pageNum, int pageSize, String name, String subjects, String province, String exam, Integer minYear, Integer maxYear) {
        return paperService.findAllByQuery(pageNum, pageSize, name, subjects, province, exam, minYear, maxYear);
    }

    @ApiOperation(value = "通过id获取试卷信息")
    @ResponseBody
    @GetMapping("/getOne")
    public PaperInfo getOne(int paperId) {
        return paperService.getOne(paperId);
    }

    @ApiOperation(value = "解析未处理的试卷")
    @ResponseBody
    @GetMapping("/parsingWordsWcl")
    public void parsingWordsWcl() {
        paperService.parsingWordsByStatus("0");
    }

    @ApiOperation(value = "解析处理异常的试卷")
    @ResponseBody
    @GetMapping("/parsingWordsYc")
    public void parsingWordsYc() {
        paperService.parsingWordsByStatus("9");
    }

    @ApiOperation(value = "删除试卷,ids传字符串，多个用','隔开")
    @ResponseBody
    @GetMapping("/delPapers")
    public String delPapers(String ids) {
        int total = paperService.delPapers(ids);
        if (total < 0) {
            return "删除失败，服务器异常！";
        } else {
            return "删除成功";
        }
    }
}
